package com.zqxq.lottery.controller.user;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.entity.po.user.UserBindPO;
import com.zqxq.lottery.entity.po.user.UserWechatPO;
import com.zqxq.lottery.service.user.IUserBindService;
import com.zqxq.lottery.service.user.IUserWechatService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/relationship")
public class UserBindController extends UserBaseController{

    @Autowired
    private IUserBindService userBindService;

    @ApiOperation("绑定关系")
    @PostMapping("/bindRelationship")
    public Result bindRelationship(Long userId, String openId){
        Result result = new Result<>();
        if(userId == null || StrUtils.isEmpty(openId)){
            return new Result<>(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        try {
            userBindService.bindRelationship(userId,openId);
        } catch (Exception e) {
            result.setCode(CodeEnum.FAIL_100005.getCode());
            result.setMsg(CodeEnum.FAIL_100005.getMsg());
        }
        return result;
    }

    @ApiOperation("获取绑定关系")
    @PostMapping("/getRelationship")
    public Result<UserBindPO> getRelationship(String openId){
        Result result = new Result<>();
        if(openId == null){
            return new Result<>(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        try {
            Wrapper wrapper = new EntityWrapper();
            wrapper.eq("open_id",openId);
            UserBindPO userBindPO = userBindService.selectOne(wrapper);
            result.setData(userBindPO);
        } catch (Exception e) {
            result.setCode(CodeEnum.FAIL_100005.getCode());
            result.setMsg(CodeEnum.FAIL_100005.getMsg());
        }
        return result;
    }

}
